{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4.1 Overview of a DataFrame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 4.1.1 Creating DataFrame from Dictionary"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>City</th>\n",
       "      <th>Country</th>\n",
       "      <th>Population</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>New York City</td>\n",
       "      <td>United States</td>\n",
       "      <td>8600000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Paris</td>\n",
       "      <td>France</td>\n",
       "      <td>2141000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Barcelona</td>\n",
       "      <td>Spain</td>\n",
       "      <td>5515000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Rome</td>\n",
       "      <td>Italy</td>\n",
       "      <td>2873000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            City        Country  Population\n",
       "0  New York City  United States     8600000\n",
       "1          Paris         France     2141000\n",
       "2      Barcelona          Spain     5515000\n",
       "3           Rome          Italy     2873000"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "city_data = {\n",
    "    \"City\": [\"New York City\", \"Paris\", \"Barcelona\", \"Rome\"],\n",
    "    \"Country\": [\"United States\", \"France\", \"Spain\", \"Italy\"],\n",
    "    \"Population\": pd.Series([8600000, 2141000, 5515000, 2873000])\n",
    "}\n",
    "\n",
    "cities = pd.DataFrame(city_data)\n",
    "cities"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>City</th>\n",
       "      <td>New York City</td>\n",
       "      <td>Paris</td>\n",
       "      <td>Barcelona</td>\n",
       "      <td>Rome</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Country</th>\n",
       "      <td>United States</td>\n",
       "      <td>France</td>\n",
       "      <td>Spain</td>\n",
       "      <td>Italy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Population</th>\n",
       "      <td>8600000</td>\n",
       "      <td>2141000</td>\n",
       "      <td>5515000</td>\n",
       "      <td>2873000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                        0        1          2        3\n",
       "City        New York City    Paris  Barcelona     Rome\n",
       "Country     United States   France      Spain    Italy\n",
       "Population        8600000  2141000    5515000  2873000"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# The two lines below are equivalent\n",
    "cities.transpose()\n",
    "cities.T"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 4.1.2 Creating a DataFrame from a NumPy ndarray"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[49, 66, 61,  7,  9],\n",
       "       [61, 97, 79, 19, 29],\n",
       "       [92, 59, 15, 54,  7]])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "random_data = np.random.randint(1, 101, [3, 5])\n",
    "random_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>49</td>\n",
       "      <td>66</td>\n",
       "      <td>61</td>\n",
       "      <td>7</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>61</td>\n",
       "      <td>97</td>\n",
       "      <td>79</td>\n",
       "      <td>19</td>\n",
       "      <td>29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>92</td>\n",
       "      <td>59</td>\n",
       "      <td>15</td>\n",
       "      <td>54</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    0   1   2   3   4\n",
       "0  49  66  61   7   9\n",
       "1  61  97  79  19  29\n",
       "2  92  59  15  54   7"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.DataFrame(data = random_data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Morning</th>\n",
       "      <td>49</td>\n",
       "      <td>66</td>\n",
       "      <td>61</td>\n",
       "      <td>7</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Afternoon</th>\n",
       "      <td>61</td>\n",
       "      <td>97</td>\n",
       "      <td>79</td>\n",
       "      <td>19</td>\n",
       "      <td>29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Evening</th>\n",
       "      <td>92</td>\n",
       "      <td>59</td>\n",
       "      <td>15</td>\n",
       "      <td>54</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            0   1   2   3   4\n",
       "Morning    49  66  61   7   9\n",
       "Afternoon  61  97  79  19  29\n",
       "Evening    92  59  15  54   7"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "row_labels = [\"Morning\", \"Afternoon\", \"Evening\"]\n",
    "temperatures = pd.DataFrame(\n",
    "    data = random_data, index = row_labels\n",
    ")\n",
    "temperatures"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Monday</th>\n",
       "      <th>Tuesday</th>\n",
       "      <th>Wednesday</th>\n",
       "      <th>Thursday</th>\n",
       "      <th>Friday</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Morning</th>\n",
       "      <td>49</td>\n",
       "      <td>66</td>\n",
       "      <td>61</td>\n",
       "      <td>7</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Afternoon</th>\n",
       "      <td>61</td>\n",
       "      <td>97</td>\n",
       "      <td>79</td>\n",
       "      <td>19</td>\n",
       "      <td>29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Evening</th>\n",
       "      <td>92</td>\n",
       "      <td>59</td>\n",
       "      <td>15</td>\n",
       "      <td>54</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           Monday  Tuesday  Wednesday  Thursday  Friday\n",
       "Morning        49       66         61         7       9\n",
       "Afternoon      61       97         79        19      29\n",
       "Evening        92       59         15        54       7"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "row_labels = [\"Morning\", \"Afternoon\", \"Evening\"]\n",
    "column_labels = (\n",
    "    \"Monday\",\n",
    "    \"Tuesday\",\n",
    "    \"Wednesday\",\n",
    "    \"Thursday\",\n",
    "    \"Friday\"\n",
    ")\n",
    "\n",
    "pd.DataFrame(\n",
    "    data = random_data,\n",
    "    index = row_labels,\n",
    "    columns = column_labels,\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Monday</th>\n",
       "      <th>Tuesday</th>\n",
       "      <th>Wednesday</th>\n",
       "      <th>Thursday</th>\n",
       "      <th>Friday</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Morning</th>\n",
       "      <td>49</td>\n",
       "      <td>66</td>\n",
       "      <td>61</td>\n",
       "      <td>7</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Afternoon</th>\n",
       "      <td>61</td>\n",
       "      <td>97</td>\n",
       "      <td>79</td>\n",
       "      <td>19</td>\n",
       "      <td>29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Morning</th>\n",
       "      <td>92</td>\n",
       "      <td>59</td>\n",
       "      <td>15</td>\n",
       "      <td>54</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           Monday  Tuesday  Wednesday  Thursday  Friday\n",
       "Morning        49       66         61         7       9\n",
       "Afternoon      61       97         79        19      29\n",
       "Morning        92       59         15        54       7"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "row_labels = [\"Morning\", \"Afternoon\", \"Morning\"]\n",
    "column_lables = [\n",
    "    \"Monday\",\n",
    "    \"Tuesday\",\n",
    "    \"Wednesday\",\n",
    "    \"Tuesday\",\n",
    "    \"Friday\"\n",
    "]\n",
    "\n",
    "pd.DataFrame(\n",
    "    data = random_data,\n",
    "    index = row_labels,\n",
    "    columns = column_labels,\n",
    ")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4.2 Similarities between Series and DataFrames"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 4.2.1 Importing a DataFrame with the read_csv Function"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Shake Milton</td>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>SG</td>\n",
       "      <td>9/26/96</td>\n",
       "      <td>1445697</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Christian Wood</td>\n",
       "      <td>Detroit Pistons</td>\n",
       "      <td>PF</td>\n",
       "      <td>9/27/95</td>\n",
       "      <td>1645357</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>PJ Washington</td>\n",
       "      <td>Charlotte Hornets</td>\n",
       "      <td>PF</td>\n",
       "      <td>8/23/98</td>\n",
       "      <td>3831840</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Derrick Rose</td>\n",
       "      <td>Detroit Pistons</td>\n",
       "      <td>PG</td>\n",
       "      <td>10/4/88</td>\n",
       "      <td>7317074</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Marial Shayok</td>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>G</td>\n",
       "      <td>7/26/95</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>445</th>\n",
       "      <td>Austin Rivers</td>\n",
       "      <td>Houston Rockets</td>\n",
       "      <td>PG</td>\n",
       "      <td>8/1/92</td>\n",
       "      <td>2174310</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>446</th>\n",
       "      <td>Harry Giles</td>\n",
       "      <td>Sacramento Kings</td>\n",
       "      <td>PF</td>\n",
       "      <td>4/22/98</td>\n",
       "      <td>2578800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>447</th>\n",
       "      <td>Robin Lopez</td>\n",
       "      <td>Milwaukee Bucks</td>\n",
       "      <td>C</td>\n",
       "      <td>4/1/88</td>\n",
       "      <td>4767000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>448</th>\n",
       "      <td>Collin Sexton</td>\n",
       "      <td>Cleveland Cavaliers</td>\n",
       "      <td>PG</td>\n",
       "      <td>1/4/99</td>\n",
       "      <td>4764960</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>449</th>\n",
       "      <td>Ricky Rubio</td>\n",
       "      <td>Phoenix Suns</td>\n",
       "      <td>PG</td>\n",
       "      <td>10/21/90</td>\n",
       "      <td>16200000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>450 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "               Name                 Team Position  Birthday    Salary\n",
       "0      Shake Milton   Philadelphia 76ers       SG   9/26/96   1445697\n",
       "1    Christian Wood      Detroit Pistons       PF   9/27/95   1645357\n",
       "2     PJ Washington    Charlotte Hornets       PF   8/23/98   3831840\n",
       "3      Derrick Rose      Detroit Pistons       PG   10/4/88   7317074\n",
       "4     Marial Shayok   Philadelphia 76ers        G   7/26/95     79568\n",
       "..              ...                  ...      ...       ...       ...\n",
       "445   Austin Rivers      Houston Rockets       PG    8/1/92   2174310\n",
       "446     Harry Giles     Sacramento Kings       PF   4/22/98   2578800\n",
       "447     Robin Lopez      Milwaukee Bucks        C    4/1/88   4767000\n",
       "448   Collin Sexton  Cleveland Cavaliers       PG    1/4/99   4764960\n",
       "449     Ricky Rubio         Phoenix Suns       PG  10/21/90  16200000\n",
       "\n",
       "[450 rows x 5 columns]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_csv(\"nba.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Shake Milton</td>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>SG</td>\n",
       "      <td>1996-09-26</td>\n",
       "      <td>1445697</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Christian Wood</td>\n",
       "      <td>Detroit Pistons</td>\n",
       "      <td>PF</td>\n",
       "      <td>1995-09-27</td>\n",
       "      <td>1645357</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>PJ Washington</td>\n",
       "      <td>Charlotte Hornets</td>\n",
       "      <td>PF</td>\n",
       "      <td>1998-08-23</td>\n",
       "      <td>3831840</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Derrick Rose</td>\n",
       "      <td>Detroit Pistons</td>\n",
       "      <td>PG</td>\n",
       "      <td>1988-10-04</td>\n",
       "      <td>7317074</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Marial Shayok</td>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>G</td>\n",
       "      <td>1995-07-26</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>445</th>\n",
       "      <td>Austin Rivers</td>\n",
       "      <td>Houston Rockets</td>\n",
       "      <td>PG</td>\n",
       "      <td>1992-08-01</td>\n",
       "      <td>2174310</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>446</th>\n",
       "      <td>Harry Giles</td>\n",
       "      <td>Sacramento Kings</td>\n",
       "      <td>PF</td>\n",
       "      <td>1998-04-22</td>\n",
       "      <td>2578800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>447</th>\n",
       "      <td>Robin Lopez</td>\n",
       "      <td>Milwaukee Bucks</td>\n",
       "      <td>C</td>\n",
       "      <td>1988-04-01</td>\n",
       "      <td>4767000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>448</th>\n",
       "      <td>Collin Sexton</td>\n",
       "      <td>Cleveland Cavaliers</td>\n",
       "      <td>PG</td>\n",
       "      <td>1999-01-04</td>\n",
       "      <td>4764960</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>449</th>\n",
       "      <td>Ricky Rubio</td>\n",
       "      <td>Phoenix Suns</td>\n",
       "      <td>PG</td>\n",
       "      <td>1990-10-21</td>\n",
       "      <td>16200000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>450 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "               Name                 Team Position   Birthday    Salary\n",
       "0      Shake Milton   Philadelphia 76ers       SG 1996-09-26   1445697\n",
       "1    Christian Wood      Detroit Pistons       PF 1995-09-27   1645357\n",
       "2     PJ Washington    Charlotte Hornets       PF 1998-08-23   3831840\n",
       "3      Derrick Rose      Detroit Pistons       PG 1988-10-04   7317074\n",
       "4     Marial Shayok   Philadelphia 76ers        G 1995-07-26     79568\n",
       "..              ...                  ...      ...        ...       ...\n",
       "445   Austin Rivers      Houston Rockets       PG 1992-08-01   2174310\n",
       "446     Harry Giles     Sacramento Kings       PF 1998-04-22   2578800\n",
       "447     Robin Lopez      Milwaukee Bucks        C 1988-04-01   4767000\n",
       "448   Collin Sexton  Cleveland Cavaliers       PG 1999-01-04   4764960\n",
       "449     Ricky Rubio         Phoenix Suns       PG 1990-10-21  16200000\n",
       "\n",
       "[450 rows x 5 columns]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_csv(\"nba.csv\", parse_dates = [\"Birthday\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "nba = pd.read_csv(\"nba.csv\", parse_dates = [\"Birthday\"])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 4.2.2 Shared and Exclusive Attributes between Series and DataFrames"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dtype('int64')"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.Series([1, 2, 3]).dtype"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Name                object\n",
       "Team                object\n",
       "Position            object\n",
       "Birthday    datetime64[ns]\n",
       "Salary               int64\n",
       "dtype: object"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.dtypes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "object            3\n",
       "int64             1\n",
       "datetime64[ns]    1\n",
       "dtype: int64"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.dtypes.value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "RangeIndex(start=0, stop=450, step=1)"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['Name', 'Team', 'Position', 'Birthday', 'Salary'], dtype='object')"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.ndim"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(450, 5)"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2250"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.size"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Name        450\n",
       "Team        450\n",
       "Position    450\n",
       "Birthday    450\n",
       "Salary      450\n",
       "dtype: int64"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.count()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2250"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.count().sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>NaN</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     A  B\n",
       "0  1.0  2\n",
       "1  NaN  3"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = {\n",
    "    \"A\": [1, np.nan],\n",
    "    \"B\": [2, 3]\n",
    "}\n",
    "\n",
    "df = pd.DataFrame(data)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.size"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "A    1\n",
       "B    2\n",
       "dtype: int64"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.count()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.count().sum()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 4.2.3 Shared Methods between Series and DataFrames"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Shake Milton</td>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>SG</td>\n",
       "      <td>1996-09-26</td>\n",
       "      <td>1445697</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Christian Wood</td>\n",
       "      <td>Detroit Pistons</td>\n",
       "      <td>PF</td>\n",
       "      <td>1995-09-27</td>\n",
       "      <td>1645357</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             Name                Team Position   Birthday   Salary\n",
       "0    Shake Milton  Philadelphia 76ers       SG 1996-09-26  1445697\n",
       "1  Christian Wood     Detroit Pistons       PF 1995-09-27  1645357"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.head(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>447</th>\n",
       "      <td>Robin Lopez</td>\n",
       "      <td>Milwaukee Bucks</td>\n",
       "      <td>C</td>\n",
       "      <td>1988-04-01</td>\n",
       "      <td>4767000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>448</th>\n",
       "      <td>Collin Sexton</td>\n",
       "      <td>Cleveland Cavaliers</td>\n",
       "      <td>PG</td>\n",
       "      <td>1999-01-04</td>\n",
       "      <td>4764960</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>449</th>\n",
       "      <td>Ricky Rubio</td>\n",
       "      <td>Phoenix Suns</td>\n",
       "      <td>PG</td>\n",
       "      <td>1990-10-21</td>\n",
       "      <td>16200000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              Name                 Team Position   Birthday    Salary\n",
       "447    Robin Lopez      Milwaukee Bucks        C 1988-04-01   4767000\n",
       "448  Collin Sexton  Cleveland Cavaliers       PG 1999-01-04   4764960\n",
       "449    Ricky Rubio         Phoenix Suns       PG 1990-10-21  16200000"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.tail(n = 3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>445</th>\n",
       "      <td>Austin Rivers</td>\n",
       "      <td>Houston Rockets</td>\n",
       "      <td>PG</td>\n",
       "      <td>1992-08-01</td>\n",
       "      <td>2174310</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>446</th>\n",
       "      <td>Harry Giles</td>\n",
       "      <td>Sacramento Kings</td>\n",
       "      <td>PF</td>\n",
       "      <td>1998-04-22</td>\n",
       "      <td>2578800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>447</th>\n",
       "      <td>Robin Lopez</td>\n",
       "      <td>Milwaukee Bucks</td>\n",
       "      <td>C</td>\n",
       "      <td>1988-04-01</td>\n",
       "      <td>4767000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>448</th>\n",
       "      <td>Collin Sexton</td>\n",
       "      <td>Cleveland Cavaliers</td>\n",
       "      <td>PG</td>\n",
       "      <td>1999-01-04</td>\n",
       "      <td>4764960</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>449</th>\n",
       "      <td>Ricky Rubio</td>\n",
       "      <td>Phoenix Suns</td>\n",
       "      <td>PG</td>\n",
       "      <td>1990-10-21</td>\n",
       "      <td>16200000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              Name                 Team Position   Birthday    Salary\n",
       "445  Austin Rivers      Houston Rockets       PG 1992-08-01   2174310\n",
       "446    Harry Giles     Sacramento Kings       PF 1998-04-22   2578800\n",
       "447    Robin Lopez      Milwaukee Bucks        C 1988-04-01   4767000\n",
       "448  Collin Sexton  Cleveland Cavaliers       PG 1999-01-04   4764960\n",
       "449    Ricky Rubio         Phoenix Suns       PG 1990-10-21  16200000"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.tail()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>226</th>\n",
       "      <td>Davis Bertans</td>\n",
       "      <td>Washington Wizards</td>\n",
       "      <td>PF</td>\n",
       "      <td>1992-11-12</td>\n",
       "      <td>7000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>119</th>\n",
       "      <td>DeMarcus Cousins</td>\n",
       "      <td>Los Angeles Lakers</td>\n",
       "      <td>C</td>\n",
       "      <td>1990-08-13</td>\n",
       "      <td>3500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>249</th>\n",
       "      <td>Markieff Morris</td>\n",
       "      <td>Detroit Pistons</td>\n",
       "      <td>PF</td>\n",
       "      <td>1989-09-02</td>\n",
       "      <td>3200000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 Name                Team Position   Birthday   Salary\n",
       "226     Davis Bertans  Washington Wizards       PF 1992-11-12  7000000\n",
       "119  DeMarcus Cousins  Los Angeles Lakers        C 1990-08-13  3500000\n",
       "249   Markieff Morris     Detroit Pistons       PF 1989-09-02  3200000"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.sample(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Name        450\n",
       "Team         30\n",
       "Position      9\n",
       "Birthday    430\n",
       "Salary      269\n",
       "dtype: int64"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.nunique()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Name             Zylan Cheatham\n",
       "Team         Washington Wizards\n",
       "Position                     SG\n",
       "Birthday    2000-12-23 00:00:00\n",
       "Salary                 40231758\n",
       "dtype: object"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.max()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Name               Aaron Gordon\n",
       "Team              Atlanta Hawks\n",
       "Position                      C\n",
       "Birthday    1977-01-26 00:00:00\n",
       "Salary                    79568\n",
       "dtype: object"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.min()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>205</th>\n",
       "      <td>Stephen Curry</td>\n",
       "      <td>Golden State Warriors</td>\n",
       "      <td>PG</td>\n",
       "      <td>1988-03-14</td>\n",
       "      <td>40231758</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38</th>\n",
       "      <td>Chris Paul</td>\n",
       "      <td>Oklahoma City Thunder</td>\n",
       "      <td>PG</td>\n",
       "      <td>1985-05-06</td>\n",
       "      <td>38506482</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>219</th>\n",
       "      <td>Russell Westbrook</td>\n",
       "      <td>Houston Rockets</td>\n",
       "      <td>PG</td>\n",
       "      <td>1988-11-12</td>\n",
       "      <td>38506482</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>251</th>\n",
       "      <td>John Wall</td>\n",
       "      <td>Washington Wizards</td>\n",
       "      <td>PG</td>\n",
       "      <td>1990-09-06</td>\n",
       "      <td>38199000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                  Name                   Team Position   Birthday    Salary\n",
       "205      Stephen Curry  Golden State Warriors       PG 1988-03-14  40231758\n",
       "38          Chris Paul  Oklahoma City Thunder       PG 1985-05-06  38506482\n",
       "219  Russell Westbrook        Houston Rockets       PG 1988-11-12  38506482\n",
       "251          John Wall     Washington Wizards       PG 1990-09-06  38199000"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.nlargest(n = 4, columns = \"Salary\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>98</th>\n",
       "      <td>Vince Carter</td>\n",
       "      <td>Atlanta Hawks</td>\n",
       "      <td>PF</td>\n",
       "      <td>1977-01-26</td>\n",
       "      <td>2564753</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>196</th>\n",
       "      <td>Udonis Haslem</td>\n",
       "      <td>Miami Heat</td>\n",
       "      <td>C</td>\n",
       "      <td>1980-06-09</td>\n",
       "      <td>2564753</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>262</th>\n",
       "      <td>Kyle Korver</td>\n",
       "      <td>Milwaukee Bucks</td>\n",
       "      <td>PF</td>\n",
       "      <td>1981-03-17</td>\n",
       "      <td>6004753</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              Name             Team Position   Birthday   Salary\n",
       "98    Vince Carter    Atlanta Hawks       PF 1977-01-26  2564753\n",
       "196  Udonis Haslem       Miami Heat        C 1980-06-09  2564753\n",
       "262    Kyle Korver  Milwaukee Bucks       PF 1981-03-17  6004753"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.nsmallest(n = 3, columns = [\"Birthday\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Name        Shake MiltonChristian WoodPJ WashingtonDerrick...\n",
       "Team        Philadelphia 76ersDetroit PistonsCharlotte Hor...\n",
       "Position    SGPFPFPGGPFSGSFCSFPGPGFCPGSGPFCCPFPFSGPFPGSGSF...\n",
       "Salary                                             3444112694\n",
       "dtype: object"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Salary    3444112694\n",
       "dtype: int64"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.sum(numeric_only = True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Salary    7.653584e+06\n",
       "dtype: float64"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.mean(numeric_only = True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Salary    3303074.5\n",
       "dtype: float64"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.median(numeric_only = True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Salary\n",
       "0   79568"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.mode(numeric_only = True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Salary    9.288810e+06\n",
       "dtype: float64"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.std(numeric_only = True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4.3 Sorting a DataFrame"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 4.3.1 Sorting by Single Column"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>52</th>\n",
       "      <td>Aaron Gordon</td>\n",
       "      <td>Orlando Magic</td>\n",
       "      <td>PF</td>\n",
       "      <td>1995-09-16</td>\n",
       "      <td>19863636</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>101</th>\n",
       "      <td>Aaron Holiday</td>\n",
       "      <td>Indiana Pacers</td>\n",
       "      <td>PG</td>\n",
       "      <td>1996-09-30</td>\n",
       "      <td>2239200</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>437</th>\n",
       "      <td>Abdel Nader</td>\n",
       "      <td>Oklahoma City Thunder</td>\n",
       "      <td>SF</td>\n",
       "      <td>1993-09-25</td>\n",
       "      <td>1618520</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>81</th>\n",
       "      <td>Adam Mokoka</td>\n",
       "      <td>Chicago Bulls</td>\n",
       "      <td>G</td>\n",
       "      <td>1998-07-18</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>399</th>\n",
       "      <td>Admiral Schofield</td>\n",
       "      <td>Washington Wizards</td>\n",
       "      <td>SF</td>\n",
       "      <td>1997-03-30</td>\n",
       "      <td>1000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>159</th>\n",
       "      <td>Zach LaVine</td>\n",
       "      <td>Chicago Bulls</td>\n",
       "      <td>PG</td>\n",
       "      <td>1995-03-10</td>\n",
       "      <td>19500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>302</th>\n",
       "      <td>Zach Norvell</td>\n",
       "      <td>Los Angeles Lakers</td>\n",
       "      <td>SG</td>\n",
       "      <td>1997-12-09</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>312</th>\n",
       "      <td>Zhaire Smith</td>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>SG</td>\n",
       "      <td>1999-06-04</td>\n",
       "      <td>3058800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>137</th>\n",
       "      <td>Zion Williamson</td>\n",
       "      <td>New Orleans Pelicans</td>\n",
       "      <td>F</td>\n",
       "      <td>2000-07-06</td>\n",
       "      <td>9757440</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>248</th>\n",
       "      <td>Zylan Cheatham</td>\n",
       "      <td>New Orleans Pelicans</td>\n",
       "      <td>SF</td>\n",
       "      <td>1995-11-17</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>450 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                  Name                   Team Position   Birthday    Salary\n",
       "52        Aaron Gordon          Orlando Magic       PF 1995-09-16  19863636\n",
       "101      Aaron Holiday         Indiana Pacers       PG 1996-09-30   2239200\n",
       "437        Abdel Nader  Oklahoma City Thunder       SF 1993-09-25   1618520\n",
       "81         Adam Mokoka          Chicago Bulls        G 1998-07-18     79568\n",
       "399  Admiral Schofield     Washington Wizards       SF 1997-03-30   1000000\n",
       "..                 ...                    ...      ...        ...       ...\n",
       "159        Zach LaVine          Chicago Bulls       PG 1995-03-10  19500000\n",
       "302       Zach Norvell     Los Angeles Lakers       SG 1997-12-09     79568\n",
       "312       Zhaire Smith     Philadelphia 76ers       SG 1999-06-04   3058800\n",
       "137    Zion Williamson   New Orleans Pelicans        F 2000-07-06   9757440\n",
       "248     Zylan Cheatham   New Orleans Pelicans       SF 1995-11-17     79568\n",
       "\n",
       "[450 rows x 5 columns]"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# The two lines below are equivalent\n",
    "nba.sort_values(\"Name\")\n",
    "nba.sort_values(by = \"Name\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>248</th>\n",
       "      <td>Zylan Cheatham</td>\n",
       "      <td>New Orleans Pelicans</td>\n",
       "      <td>SF</td>\n",
       "      <td>1995-11-17</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>137</th>\n",
       "      <td>Zion Williamson</td>\n",
       "      <td>New Orleans Pelicans</td>\n",
       "      <td>F</td>\n",
       "      <td>2000-07-06</td>\n",
       "      <td>9757440</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>312</th>\n",
       "      <td>Zhaire Smith</td>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>SG</td>\n",
       "      <td>1999-06-04</td>\n",
       "      <td>3058800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>302</th>\n",
       "      <td>Zach Norvell</td>\n",
       "      <td>Los Angeles Lakers</td>\n",
       "      <td>SG</td>\n",
       "      <td>1997-12-09</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>159</th>\n",
       "      <td>Zach LaVine</td>\n",
       "      <td>Chicago Bulls</td>\n",
       "      <td>PG</td>\n",
       "      <td>1995-03-10</td>\n",
       "      <td>19500000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                Name                  Team Position   Birthday    Salary\n",
       "248   Zylan Cheatham  New Orleans Pelicans       SF 1995-11-17     79568\n",
       "137  Zion Williamson  New Orleans Pelicans        F 2000-07-06   9757440\n",
       "312     Zhaire Smith    Philadelphia 76ers       SG 1999-06-04   3058800\n",
       "302     Zach Norvell    Los Angeles Lakers       SG 1997-12-09     79568\n",
       "159      Zach LaVine         Chicago Bulls       PG 1995-03-10  19500000"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.sort_values(\"Name\", ascending = False).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>136</th>\n",
       "      <td>Sekou Doumbouya</td>\n",
       "      <td>Detroit Pistons</td>\n",
       "      <td>SF</td>\n",
       "      <td>2000-12-23</td>\n",
       "      <td>3285120</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>432</th>\n",
       "      <td>Talen Horton-Tucker</td>\n",
       "      <td>Los Angeles Lakers</td>\n",
       "      <td>GF</td>\n",
       "      <td>2000-11-25</td>\n",
       "      <td>898310</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>137</th>\n",
       "      <td>Zion Williamson</td>\n",
       "      <td>New Orleans Pelicans</td>\n",
       "      <td>F</td>\n",
       "      <td>2000-07-06</td>\n",
       "      <td>9757440</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>313</th>\n",
       "      <td>RJ Barrett</td>\n",
       "      <td>New York Knicks</td>\n",
       "      <td>SG</td>\n",
       "      <td>2000-06-14</td>\n",
       "      <td>7839960</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>392</th>\n",
       "      <td>Jalen Lecque</td>\n",
       "      <td>Phoenix Suns</td>\n",
       "      <td>G</td>\n",
       "      <td>2000-06-13</td>\n",
       "      <td>898310</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                    Name                  Team Position   Birthday   Salary\n",
       "136      Sekou Doumbouya       Detroit Pistons       SF 2000-12-23  3285120\n",
       "432  Talen Horton-Tucker    Los Angeles Lakers       GF 2000-11-25   898310\n",
       "137      Zion Williamson  New Orleans Pelicans        F 2000-07-06  9757440\n",
       "313           RJ Barrett       New York Knicks       SG 2000-06-14  7839960\n",
       "392         Jalen Lecque          Phoenix Suns        G 2000-06-13   898310"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.sort_values(\"Birthday\", ascending = False).head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 4.3.2 Sorting by Multiple Columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>359</th>\n",
       "      <td>Alex Len</td>\n",
       "      <td>Atlanta Hawks</td>\n",
       "      <td>C</td>\n",
       "      <td>1993-06-16</td>\n",
       "      <td>4160000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>167</th>\n",
       "      <td>Allen Crabbe</td>\n",
       "      <td>Atlanta Hawks</td>\n",
       "      <td>SG</td>\n",
       "      <td>1992-04-09</td>\n",
       "      <td>18500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>276</th>\n",
       "      <td>Brandon Goodwin</td>\n",
       "      <td>Atlanta Hawks</td>\n",
       "      <td>PG</td>\n",
       "      <td>1995-10-02</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>438</th>\n",
       "      <td>Bruno Fernando</td>\n",
       "      <td>Atlanta Hawks</td>\n",
       "      <td>C</td>\n",
       "      <td>1998-08-15</td>\n",
       "      <td>1400000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>194</th>\n",
       "      <td>Cam Reddish</td>\n",
       "      <td>Atlanta Hawks</td>\n",
       "      <td>SF</td>\n",
       "      <td>1999-09-01</td>\n",
       "      <td>4245720</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>418</th>\n",
       "      <td>Jordan McRae</td>\n",
       "      <td>Washington Wizards</td>\n",
       "      <td>PG</td>\n",
       "      <td>1991-03-28</td>\n",
       "      <td>1645357</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>273</th>\n",
       "      <td>Justin Robinson</td>\n",
       "      <td>Washington Wizards</td>\n",
       "      <td>PG</td>\n",
       "      <td>1997-10-12</td>\n",
       "      <td>898310</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>428</th>\n",
       "      <td>Moritz Wagner</td>\n",
       "      <td>Washington Wizards</td>\n",
       "      <td>C</td>\n",
       "      <td>1997-04-26</td>\n",
       "      <td>2063520</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>Rui Hachimura</td>\n",
       "      <td>Washington Wizards</td>\n",
       "      <td>PF</td>\n",
       "      <td>1998-02-08</td>\n",
       "      <td>4469160</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>36</th>\n",
       "      <td>Thomas Bryant</td>\n",
       "      <td>Washington Wizards</td>\n",
       "      <td>C</td>\n",
       "      <td>1997-07-31</td>\n",
       "      <td>8000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>450 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                Name                Team Position   Birthday    Salary\n",
       "359         Alex Len       Atlanta Hawks        C 1993-06-16   4160000\n",
       "167     Allen Crabbe       Atlanta Hawks       SG 1992-04-09  18500000\n",
       "276  Brandon Goodwin       Atlanta Hawks       PG 1995-10-02     79568\n",
       "438   Bruno Fernando       Atlanta Hawks        C 1998-08-15   1400000\n",
       "194      Cam Reddish       Atlanta Hawks       SF 1999-09-01   4245720\n",
       "..               ...                 ...      ...        ...       ...\n",
       "418     Jordan McRae  Washington Wizards       PG 1991-03-28   1645357\n",
       "273  Justin Robinson  Washington Wizards       PG 1997-10-12    898310\n",
       "428    Moritz Wagner  Washington Wizards        C 1997-04-26   2063520\n",
       "21     Rui Hachimura  Washington Wizards       PF 1998-02-08   4469160\n",
       "36     Thomas Bryant  Washington Wizards        C 1997-07-31   8000000\n",
       "\n",
       "[450 rows x 5 columns]"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.sort_values(by = [\"Team\", \"Name\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>36</th>\n",
       "      <td>Thomas Bryant</td>\n",
       "      <td>Washington Wizards</td>\n",
       "      <td>C</td>\n",
       "      <td>1997-07-31</td>\n",
       "      <td>8000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>Rui Hachimura</td>\n",
       "      <td>Washington Wizards</td>\n",
       "      <td>PF</td>\n",
       "      <td>1998-02-08</td>\n",
       "      <td>4469160</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>428</th>\n",
       "      <td>Moritz Wagner</td>\n",
       "      <td>Washington Wizards</td>\n",
       "      <td>C</td>\n",
       "      <td>1997-04-26</td>\n",
       "      <td>2063520</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>273</th>\n",
       "      <td>Justin Robinson</td>\n",
       "      <td>Washington Wizards</td>\n",
       "      <td>PG</td>\n",
       "      <td>1997-10-12</td>\n",
       "      <td>898310</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>418</th>\n",
       "      <td>Jordan McRae</td>\n",
       "      <td>Washington Wizards</td>\n",
       "      <td>PG</td>\n",
       "      <td>1991-03-28</td>\n",
       "      <td>1645357</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>194</th>\n",
       "      <td>Cam Reddish</td>\n",
       "      <td>Atlanta Hawks</td>\n",
       "      <td>SF</td>\n",
       "      <td>1999-09-01</td>\n",
       "      <td>4245720</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>438</th>\n",
       "      <td>Bruno Fernando</td>\n",
       "      <td>Atlanta Hawks</td>\n",
       "      <td>C</td>\n",
       "      <td>1998-08-15</td>\n",
       "      <td>1400000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>276</th>\n",
       "      <td>Brandon Goodwin</td>\n",
       "      <td>Atlanta Hawks</td>\n",
       "      <td>PG</td>\n",
       "      <td>1995-10-02</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>167</th>\n",
       "      <td>Allen Crabbe</td>\n",
       "      <td>Atlanta Hawks</td>\n",
       "      <td>SG</td>\n",
       "      <td>1992-04-09</td>\n",
       "      <td>18500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>359</th>\n",
       "      <td>Alex Len</td>\n",
       "      <td>Atlanta Hawks</td>\n",
       "      <td>C</td>\n",
       "      <td>1993-06-16</td>\n",
       "      <td>4160000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>450 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                Name                Team Position   Birthday    Salary\n",
       "36     Thomas Bryant  Washington Wizards        C 1997-07-31   8000000\n",
       "21     Rui Hachimura  Washington Wizards       PF 1998-02-08   4469160\n",
       "428    Moritz Wagner  Washington Wizards        C 1997-04-26   2063520\n",
       "273  Justin Robinson  Washington Wizards       PG 1997-10-12    898310\n",
       "418     Jordan McRae  Washington Wizards       PG 1991-03-28   1645357\n",
       "..               ...                 ...      ...        ...       ...\n",
       "194      Cam Reddish       Atlanta Hawks       SF 1999-09-01   4245720\n",
       "438   Bruno Fernando       Atlanta Hawks        C 1998-08-15   1400000\n",
       "276  Brandon Goodwin       Atlanta Hawks       PG 1995-10-02     79568\n",
       "167     Allen Crabbe       Atlanta Hawks       SG 1992-04-09  18500000\n",
       "359         Alex Len       Atlanta Hawks        C 1993-06-16   4160000\n",
       "\n",
       "[450 rows x 5 columns]"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.sort_values([\"Team\", \"Name\"], ascending = False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>111</th>\n",
       "      <td>Chandler Parsons</td>\n",
       "      <td>Atlanta Hawks</td>\n",
       "      <td>SF</td>\n",
       "      <td>1988-10-25</td>\n",
       "      <td>25102512</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>Evan Turner</td>\n",
       "      <td>Atlanta Hawks</td>\n",
       "      <td>PG</td>\n",
       "      <td>1988-10-27</td>\n",
       "      <td>18606556</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>167</th>\n",
       "      <td>Allen Crabbe</td>\n",
       "      <td>Atlanta Hawks</td>\n",
       "      <td>SG</td>\n",
       "      <td>1992-04-09</td>\n",
       "      <td>18500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>213</th>\n",
       "      <td>De'Andre Hunter</td>\n",
       "      <td>Atlanta Hawks</td>\n",
       "      <td>SF</td>\n",
       "      <td>1997-12-02</td>\n",
       "      <td>7068360</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>339</th>\n",
       "      <td>Jabari Parker</td>\n",
       "      <td>Atlanta Hawks</td>\n",
       "      <td>PF</td>\n",
       "      <td>1995-03-15</td>\n",
       "      <td>6500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80</th>\n",
       "      <td>Isaac Bonga</td>\n",
       "      <td>Washington Wizards</td>\n",
       "      <td>PG</td>\n",
       "      <td>1999-11-08</td>\n",
       "      <td>1416852</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>399</th>\n",
       "      <td>Admiral Schofield</td>\n",
       "      <td>Washington Wizards</td>\n",
       "      <td>SF</td>\n",
       "      <td>1997-03-30</td>\n",
       "      <td>1000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>273</th>\n",
       "      <td>Justin Robinson</td>\n",
       "      <td>Washington Wizards</td>\n",
       "      <td>PG</td>\n",
       "      <td>1997-10-12</td>\n",
       "      <td>898310</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>283</th>\n",
       "      <td>Garrison Mathews</td>\n",
       "      <td>Washington Wizards</td>\n",
       "      <td>SG</td>\n",
       "      <td>1996-10-24</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>353</th>\n",
       "      <td>Chris Chiozza</td>\n",
       "      <td>Washington Wizards</td>\n",
       "      <td>PG</td>\n",
       "      <td>1995-11-21</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>450 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                  Name                Team Position   Birthday    Salary\n",
       "111   Chandler Parsons       Atlanta Hawks       SF 1988-10-25  25102512\n",
       "28         Evan Turner       Atlanta Hawks       PG 1988-10-27  18606556\n",
       "167       Allen Crabbe       Atlanta Hawks       SG 1992-04-09  18500000\n",
       "213    De'Andre Hunter       Atlanta Hawks       SF 1997-12-02   7068360\n",
       "339      Jabari Parker       Atlanta Hawks       PF 1995-03-15   6500000\n",
       "..                 ...                 ...      ...        ...       ...\n",
       "80         Isaac Bonga  Washington Wizards       PG 1999-11-08   1416852\n",
       "399  Admiral Schofield  Washington Wizards       SF 1997-03-30   1000000\n",
       "273    Justin Robinson  Washington Wizards       PG 1997-10-12    898310\n",
       "283   Garrison Mathews  Washington Wizards       SG 1996-10-24     79568\n",
       "353      Chris Chiozza  Washington Wizards       PG 1995-11-21     79568\n",
       "\n",
       "[450 rows x 5 columns]"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.sort_values(\n",
    "    by = [\"Team\", \"Salary\"], ascending = [True, False]\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [],
   "source": [
    "nba = nba.sort_values(\n",
    "    by = [\"Team\", \"Salary\"],\n",
    "    ascending = [True, False]\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4.4 Sorting by Index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>111</th>\n",
       "      <td>Chandler Parsons</td>\n",
       "      <td>Atlanta Hawks</td>\n",
       "      <td>SF</td>\n",
       "      <td>1988-10-25</td>\n",
       "      <td>25102512</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>Evan Turner</td>\n",
       "      <td>Atlanta Hawks</td>\n",
       "      <td>PG</td>\n",
       "      <td>1988-10-27</td>\n",
       "      <td>18606556</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>167</th>\n",
       "      <td>Allen Crabbe</td>\n",
       "      <td>Atlanta Hawks</td>\n",
       "      <td>SG</td>\n",
       "      <td>1992-04-09</td>\n",
       "      <td>18500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>213</th>\n",
       "      <td>De'Andre Hunter</td>\n",
       "      <td>Atlanta Hawks</td>\n",
       "      <td>SF</td>\n",
       "      <td>1997-12-02</td>\n",
       "      <td>7068360</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>339</th>\n",
       "      <td>Jabari Parker</td>\n",
       "      <td>Atlanta Hawks</td>\n",
       "      <td>PF</td>\n",
       "      <td>1995-03-15</td>\n",
       "      <td>6500000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 Name           Team Position   Birthday    Salary\n",
       "111  Chandler Parsons  Atlanta Hawks       SF 1988-10-25  25102512\n",
       "28        Evan Turner  Atlanta Hawks       PG 1988-10-27  18606556\n",
       "167      Allen Crabbe  Atlanta Hawks       SG 1992-04-09  18500000\n",
       "213   De'Andre Hunter  Atlanta Hawks       SF 1997-12-02   7068360\n",
       "339     Jabari Parker  Atlanta Hawks       PF 1995-03-15   6500000"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 4.4.1 Sorting by Row Index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Shake Milton</td>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>SG</td>\n",
       "      <td>1996-09-26</td>\n",
       "      <td>1445697</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Christian Wood</td>\n",
       "      <td>Detroit Pistons</td>\n",
       "      <td>PF</td>\n",
       "      <td>1995-09-27</td>\n",
       "      <td>1645357</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>PJ Washington</td>\n",
       "      <td>Charlotte Hornets</td>\n",
       "      <td>PF</td>\n",
       "      <td>1998-08-23</td>\n",
       "      <td>3831840</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Derrick Rose</td>\n",
       "      <td>Detroit Pistons</td>\n",
       "      <td>PG</td>\n",
       "      <td>1988-10-04</td>\n",
       "      <td>7317074</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Marial Shayok</td>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>G</td>\n",
       "      <td>1995-07-26</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             Name                Team Position   Birthday   Salary\n",
       "0    Shake Milton  Philadelphia 76ers       SG 1996-09-26  1445697\n",
       "1  Christian Wood     Detroit Pistons       PF 1995-09-27  1645357\n",
       "2   PJ Washington   Charlotte Hornets       PF 1998-08-23  3831840\n",
       "3    Derrick Rose     Detroit Pistons       PG 1988-10-04  7317074\n",
       "4   Marial Shayok  Philadelphia 76ers        G 1995-07-26    79568"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# The two lines below are equivalent\n",
    "nba.sort_index().head()\n",
    "nba.sort_index(ascending = True).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>449</th>\n",
       "      <td>Ricky Rubio</td>\n",
       "      <td>Phoenix Suns</td>\n",
       "      <td>PG</td>\n",
       "      <td>1990-10-21</td>\n",
       "      <td>16200000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>448</th>\n",
       "      <td>Collin Sexton</td>\n",
       "      <td>Cleveland Cavaliers</td>\n",
       "      <td>PG</td>\n",
       "      <td>1999-01-04</td>\n",
       "      <td>4764960</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>447</th>\n",
       "      <td>Robin Lopez</td>\n",
       "      <td>Milwaukee Bucks</td>\n",
       "      <td>C</td>\n",
       "      <td>1988-04-01</td>\n",
       "      <td>4767000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>446</th>\n",
       "      <td>Harry Giles</td>\n",
       "      <td>Sacramento Kings</td>\n",
       "      <td>PF</td>\n",
       "      <td>1998-04-22</td>\n",
       "      <td>2578800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>445</th>\n",
       "      <td>Austin Rivers</td>\n",
       "      <td>Houston Rockets</td>\n",
       "      <td>PG</td>\n",
       "      <td>1992-08-01</td>\n",
       "      <td>2174310</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              Name                 Team Position   Birthday    Salary\n",
       "449    Ricky Rubio         Phoenix Suns       PG 1990-10-21  16200000\n",
       "448  Collin Sexton  Cleveland Cavaliers       PG 1999-01-04   4764960\n",
       "447    Robin Lopez      Milwaukee Bucks        C 1988-04-01   4767000\n",
       "446    Harry Giles     Sacramento Kings       PF 1998-04-22   2578800\n",
       "445  Austin Rivers      Houston Rockets       PG 1992-08-01   2174310"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.sort_index(ascending = False).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [],
   "source": [
    "nba = nba.sort_index()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 4.4.2 Sorting by Column Index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Name</th>\n",
       "      <th>Position</th>\n",
       "      <th>Salary</th>\n",
       "      <th>Team</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1996-09-26</td>\n",
       "      <td>Shake Milton</td>\n",
       "      <td>SG</td>\n",
       "      <td>1445697</td>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1995-09-27</td>\n",
       "      <td>Christian Wood</td>\n",
       "      <td>PF</td>\n",
       "      <td>1645357</td>\n",
       "      <td>Detroit Pistons</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1998-08-23</td>\n",
       "      <td>PJ Washington</td>\n",
       "      <td>PF</td>\n",
       "      <td>3831840</td>\n",
       "      <td>Charlotte Hornets</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1988-10-04</td>\n",
       "      <td>Derrick Rose</td>\n",
       "      <td>PG</td>\n",
       "      <td>7317074</td>\n",
       "      <td>Detroit Pistons</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1995-07-26</td>\n",
       "      <td>Marial Shayok</td>\n",
       "      <td>G</td>\n",
       "      <td>79568</td>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    Birthday            Name Position   Salary                Team\n",
       "0 1996-09-26    Shake Milton       SG  1445697  Philadelphia 76ers\n",
       "1 1995-09-27  Christian Wood       PF  1645357     Detroit Pistons\n",
       "2 1998-08-23   PJ Washington       PF  3831840   Charlotte Hornets\n",
       "3 1988-10-04    Derrick Rose       PG  7317074     Detroit Pistons\n",
       "4 1995-07-26   Marial Shayok        G    79568  Philadelphia 76ers"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# The two lines below are equivalent\n",
    "nba.sort_index(axis = \"columns\").head()\n",
    "nba.sort_index(axis = 1).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Team</th>\n",
       "      <th>Salary</th>\n",
       "      <th>Position</th>\n",
       "      <th>Name</th>\n",
       "      <th>Birthday</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>1445697</td>\n",
       "      <td>SG</td>\n",
       "      <td>Shake Milton</td>\n",
       "      <td>1996-09-26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Detroit Pistons</td>\n",
       "      <td>1645357</td>\n",
       "      <td>PF</td>\n",
       "      <td>Christian Wood</td>\n",
       "      <td>1995-09-27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Charlotte Hornets</td>\n",
       "      <td>3831840</td>\n",
       "      <td>PF</td>\n",
       "      <td>PJ Washington</td>\n",
       "      <td>1998-08-23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Detroit Pistons</td>\n",
       "      <td>7317074</td>\n",
       "      <td>PG</td>\n",
       "      <td>Derrick Rose</td>\n",
       "      <td>1988-10-04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>79568</td>\n",
       "      <td>G</td>\n",
       "      <td>Marial Shayok</td>\n",
       "      <td>1995-07-26</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 Team   Salary Position            Name   Birthday\n",
       "0  Philadelphia 76ers  1445697       SG    Shake Milton 1996-09-26\n",
       "1     Detroit Pistons  1645357       PF  Christian Wood 1995-09-27\n",
       "2   Charlotte Hornets  3831840       PF   PJ Washington 1998-08-23\n",
       "3     Detroit Pistons  7317074       PG    Derrick Rose 1988-10-04\n",
       "4  Philadelphia 76ers    79568        G   Marial Shayok 1995-07-26"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.sort_index(axis = \"columns\", ascending = False).head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4.5 Setting a New Index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Shake Milton</th>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>SG</td>\n",
       "      <td>1996-09-26</td>\n",
       "      <td>1445697</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Christian Wood</th>\n",
       "      <td>Detroit Pistons</td>\n",
       "      <td>PF</td>\n",
       "      <td>1995-09-27</td>\n",
       "      <td>1645357</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PJ Washington</th>\n",
       "      <td>Charlotte Hornets</td>\n",
       "      <td>PF</td>\n",
       "      <td>1998-08-23</td>\n",
       "      <td>3831840</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Derrick Rose</th>\n",
       "      <td>Detroit Pistons</td>\n",
       "      <td>PG</td>\n",
       "      <td>1988-10-04</td>\n",
       "      <td>7317074</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Marial Shayok</th>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>G</td>\n",
       "      <td>1995-07-26</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Austin Rivers</th>\n",
       "      <td>Houston Rockets</td>\n",
       "      <td>PG</td>\n",
       "      <td>1992-08-01</td>\n",
       "      <td>2174310</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Harry Giles</th>\n",
       "      <td>Sacramento Kings</td>\n",
       "      <td>PF</td>\n",
       "      <td>1998-04-22</td>\n",
       "      <td>2578800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Robin Lopez</th>\n",
       "      <td>Milwaukee Bucks</td>\n",
       "      <td>C</td>\n",
       "      <td>1988-04-01</td>\n",
       "      <td>4767000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Collin Sexton</th>\n",
       "      <td>Cleveland Cavaliers</td>\n",
       "      <td>PG</td>\n",
       "      <td>1999-01-04</td>\n",
       "      <td>4764960</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Ricky Rubio</th>\n",
       "      <td>Phoenix Suns</td>\n",
       "      <td>PG</td>\n",
       "      <td>1990-10-21</td>\n",
       "      <td>16200000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>450 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                               Team Position   Birthday    Salary\n",
       "Name                                                             \n",
       "Shake Milton     Philadelphia 76ers       SG 1996-09-26   1445697\n",
       "Christian Wood      Detroit Pistons       PF 1995-09-27   1645357\n",
       "PJ Washington     Charlotte Hornets       PF 1998-08-23   3831840\n",
       "Derrick Rose        Detroit Pistons       PG 1988-10-04   7317074\n",
       "Marial Shayok    Philadelphia 76ers        G 1995-07-26     79568\n",
       "...                             ...      ...        ...       ...\n",
       "Austin Rivers       Houston Rockets       PG 1992-08-01   2174310\n",
       "Harry Giles        Sacramento Kings       PF 1998-04-22   2578800\n",
       "Robin Lopez         Milwaukee Bucks        C 1988-04-01   4767000\n",
       "Collin Sexton   Cleveland Cavaliers       PG 1999-01-04   4764960\n",
       "Ricky Rubio            Phoenix Suns       PG 1990-10-21  16200000\n",
       "\n",
       "[450 rows x 4 columns]"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# The two lines below are equivalent\n",
    "nba.set_index(keys = \"Name\")\n",
    "nba.set_index(\"Name\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [],
   "source": [
    "nba = nba.set_index(keys = \"Name\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [],
   "source": [
    "nba = pd.read_csv(\n",
    "    \"nba.csv\", parse_dates = [\"Birthday\"], index_col = \"Name\"\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4.6 Selecting Columns and Rows from a DataFrame"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 4.6.1 Selecting a Single Column from a DataFrame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Name\n",
       "Shake Milton       1445697\n",
       "Christian Wood     1645357\n",
       "PJ Washington      3831840\n",
       "Derrick Rose       7317074\n",
       "Marial Shayok        79568\n",
       "                    ...   \n",
       "Austin Rivers      2174310\n",
       "Harry Giles        2578800\n",
       "Robin Lopez        4767000\n",
       "Collin Sexton      4764960\n",
       "Ricky Rubio       16200000\n",
       "Name: Salary, Length: 450, dtype: int64"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.Salary"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Name\n",
       "Shake Milton      SG\n",
       "Christian Wood    PF\n",
       "PJ Washington     PF\n",
       "Derrick Rose      PG\n",
       "Marial Shayok      G\n",
       "                  ..\n",
       "Austin Rivers     PG\n",
       "Harry Giles       PF\n",
       "Robin Lopez        C\n",
       "Collin Sexton     PG\n",
       "Ricky Rubio       PG\n",
       "Name: Position, Length: 450, dtype: object"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba[\"Position\"]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 4.6.2 Selecting Multiple Columns from a DataFrame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Salary</th>\n",
       "      <th>Birthday</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Shake Milton</th>\n",
       "      <td>1445697</td>\n",
       "      <td>1996-09-26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Christian Wood</th>\n",
       "      <td>1645357</td>\n",
       "      <td>1995-09-27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PJ Washington</th>\n",
       "      <td>3831840</td>\n",
       "      <td>1998-08-23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Derrick Rose</th>\n",
       "      <td>7317074</td>\n",
       "      <td>1988-10-04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Marial Shayok</th>\n",
       "      <td>79568</td>\n",
       "      <td>1995-07-26</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 Salary   Birthday\n",
       "Name                              \n",
       "Shake Milton    1445697 1996-09-26\n",
       "Christian Wood  1645357 1995-09-27\n",
       "PJ Washington   3831840 1998-08-23\n",
       "Derrick Rose    7317074 1988-10-04\n",
       "Marial Shayok     79568 1995-07-26"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba[[\"Salary\", \"Birthday\"]].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Shake Milton</th>\n",
       "      <td>1996-09-26</td>\n",
       "      <td>1445697</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Christian Wood</th>\n",
       "      <td>1995-09-27</td>\n",
       "      <td>1645357</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PJ Washington</th>\n",
       "      <td>1998-08-23</td>\n",
       "      <td>3831840</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Derrick Rose</th>\n",
       "      <td>1988-10-04</td>\n",
       "      <td>7317074</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Marial Shayok</th>\n",
       "      <td>1995-07-26</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 Birthday   Salary\n",
       "Name                              \n",
       "Shake Milton   1996-09-26  1445697\n",
       "Christian Wood 1995-09-27  1645357\n",
       "PJ Washington  1998-08-23  3831840\n",
       "Derrick Rose   1988-10-04  7317074\n",
       "Marial Shayok  1995-07-26    79568"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba[[\"Birthday\", \"Salary\"]].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Shake Milton</th>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>SG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Christian Wood</th>\n",
       "      <td>Detroit Pistons</td>\n",
       "      <td>PF</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PJ Washington</th>\n",
       "      <td>Charlotte Hornets</td>\n",
       "      <td>PF</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Derrick Rose</th>\n",
       "      <td>Detroit Pistons</td>\n",
       "      <td>PG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Marial Shayok</th>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Austin Rivers</th>\n",
       "      <td>Houston Rockets</td>\n",
       "      <td>PG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Harry Giles</th>\n",
       "      <td>Sacramento Kings</td>\n",
       "      <td>PF</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Robin Lopez</th>\n",
       "      <td>Milwaukee Bucks</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Collin Sexton</th>\n",
       "      <td>Cleveland Cavaliers</td>\n",
       "      <td>PG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Ricky Rubio</th>\n",
       "      <td>Phoenix Suns</td>\n",
       "      <td>PG</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>450 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                               Team Position\n",
       "Name                                        \n",
       "Shake Milton     Philadelphia 76ers       SG\n",
       "Christian Wood      Detroit Pistons       PF\n",
       "PJ Washington     Charlotte Hornets       PF\n",
       "Derrick Rose        Detroit Pistons       PG\n",
       "Marial Shayok    Philadelphia 76ers        G\n",
       "...                             ...      ...\n",
       "Austin Rivers       Houston Rockets       PG\n",
       "Harry Giles        Sacramento Kings       PF\n",
       "Robin Lopez         Milwaukee Bucks        C\n",
       "Collin Sexton   Cleveland Cavaliers       PG\n",
       "Ricky Rubio            Phoenix Suns       PG\n",
       "\n",
       "[450 rows x 2 columns]"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.select_dtypes(include = \"object\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Birthday</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Name</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Shake Milton</th>\n",
       "      <td>1996-09-26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Christian Wood</th>\n",
       "      <td>1995-09-27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PJ Washington</th>\n",
       "      <td>1998-08-23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Derrick Rose</th>\n",
       "      <td>1988-10-04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Marial Shayok</th>\n",
       "      <td>1995-07-26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Austin Rivers</th>\n",
       "      <td>1992-08-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Harry Giles</th>\n",
       "      <td>1998-04-22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Robin Lopez</th>\n",
       "      <td>1988-04-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Collin Sexton</th>\n",
       "      <td>1999-01-04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Ricky Rubio</th>\n",
       "      <td>1990-10-21</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>450 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                 Birthday\n",
       "Name                     \n",
       "Shake Milton   1996-09-26\n",
       "Christian Wood 1995-09-27\n",
       "PJ Washington  1998-08-23\n",
       "Derrick Rose   1988-10-04\n",
       "Marial Shayok  1995-07-26\n",
       "...                   ...\n",
       "Austin Rivers  1992-08-01\n",
       "Harry Giles    1998-04-22\n",
       "Robin Lopez    1988-04-01\n",
       "Collin Sexton  1999-01-04\n",
       "Ricky Rubio    1990-10-21\n",
       "\n",
       "[450 rows x 1 columns]"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.select_dtypes(exclude = [\"object\", \"int\"])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4.7 Selecting Rows from a DataFrame"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 4.7.1 Extracting Rows by Index Label"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Team         Los Angeles Lakers\n",
       "Position                     PF\n",
       "Birthday    1984-12-30 00:00:00\n",
       "Salary                 37436858\n",
       "Name: LeBron James, dtype: object"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.loc[\"LeBron James\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Kawhi Leonard</th>\n",
       "      <td>Los Angeles Clippers</td>\n",
       "      <td>SF</td>\n",
       "      <td>1991-06-29</td>\n",
       "      <td>32742000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Paul George</th>\n",
       "      <td>Los Angeles Clippers</td>\n",
       "      <td>SF</td>\n",
       "      <td>1990-05-02</td>\n",
       "      <td>33005556</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                               Team Position   Birthday    Salary\n",
       "Name                                                             \n",
       "Kawhi Leonard  Los Angeles Clippers       SF 1991-06-29  32742000\n",
       "Paul George    Los Angeles Clippers       SF 1990-05-02  33005556"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.loc[[\"Kawhi Leonard\", \"Paul George\"]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Paul George</th>\n",
       "      <td>Los Angeles Clippers</td>\n",
       "      <td>SF</td>\n",
       "      <td>1990-05-02</td>\n",
       "      <td>33005556</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Kawhi Leonard</th>\n",
       "      <td>Los Angeles Clippers</td>\n",
       "      <td>SF</td>\n",
       "      <td>1991-06-29</td>\n",
       "      <td>32742000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                               Team Position   Birthday    Salary\n",
       "Name                                                             \n",
       "Paul George    Los Angeles Clippers       SF 1990-05-02  33005556\n",
       "Kawhi Leonard  Los Angeles Clippers       SF 1991-06-29  32742000"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.loc[[\"Paul George\", \"Kawhi Leonard\"]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Otto Porter</th>\n",
       "      <td>Chicago Bulls</td>\n",
       "      <td>SF</td>\n",
       "      <td>1993-06-03</td>\n",
       "      <td>27250576</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PJ Dozier</th>\n",
       "      <td>Denver Nuggets</td>\n",
       "      <td>PG</td>\n",
       "      <td>1996-10-25</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PJ Washington</th>\n",
       "      <td>Charlotte Hornets</td>\n",
       "      <td>PF</td>\n",
       "      <td>1998-08-23</td>\n",
       "      <td>3831840</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Pascal Siakam</th>\n",
       "      <td>Toronto Raptors</td>\n",
       "      <td>PF</td>\n",
       "      <td>1994-04-02</td>\n",
       "      <td>2351838</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Pat Connaughton</th>\n",
       "      <td>Milwaukee Bucks</td>\n",
       "      <td>SG</td>\n",
       "      <td>1993-01-06</td>\n",
       "      <td>1723050</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Patrick Beverley</th>\n",
       "      <td>Los Angeles Clippers</td>\n",
       "      <td>PG</td>\n",
       "      <td>1988-07-12</td>\n",
       "      <td>12345680</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                  Team Position   Birthday    Salary\n",
       "Name                                                                \n",
       "Otto Porter              Chicago Bulls       SF 1993-06-03  27250576\n",
       "PJ Dozier               Denver Nuggets       PG 1996-10-25     79568\n",
       "PJ Washington        Charlotte Hornets       PF 1998-08-23   3831840\n",
       "Pascal Siakam          Toronto Raptors       PF 1994-04-02   2351838\n",
       "Pat Connaughton        Milwaukee Bucks       SG 1993-01-06   1723050\n",
       "Patrick Beverley  Los Angeles Clippers       PG 1988-07-12  12345680"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.sort_index().loc[\"Otto Porter\":\"Patrick Beverley\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Otto Porter', 'PJ Dozier']"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "players = [\"Otto Porter\", \"PJ Dozier\", \"PJ Washington\"]\n",
    "players[0:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Zach Collins</th>\n",
       "      <td>Portland Trail Blazers</td>\n",
       "      <td>C</td>\n",
       "      <td>1997-11-19</td>\n",
       "      <td>4240200</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Zach LaVine</th>\n",
       "      <td>Chicago Bulls</td>\n",
       "      <td>PG</td>\n",
       "      <td>1995-03-10</td>\n",
       "      <td>19500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Zach Norvell</th>\n",
       "      <td>Los Angeles Lakers</td>\n",
       "      <td>SG</td>\n",
       "      <td>1997-12-09</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Zhaire Smith</th>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>SG</td>\n",
       "      <td>1999-06-04</td>\n",
       "      <td>3058800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Zion Williamson</th>\n",
       "      <td>New Orleans Pelicans</td>\n",
       "      <td>F</td>\n",
       "      <td>2000-07-06</td>\n",
       "      <td>9757440</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Zylan Cheatham</th>\n",
       "      <td>New Orleans Pelicans</td>\n",
       "      <td>SF</td>\n",
       "      <td>1995-11-17</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                   Team Position   Birthday    Salary\n",
       "Name                                                                 \n",
       "Zach Collins     Portland Trail Blazers        C 1997-11-19   4240200\n",
       "Zach LaVine               Chicago Bulls       PG 1995-03-10  19500000\n",
       "Zach Norvell         Los Angeles Lakers       SG 1997-12-09     79568\n",
       "Zhaire Smith         Philadelphia 76ers       SG 1999-06-04   3058800\n",
       "Zion Williamson    New Orleans Pelicans        F 2000-07-06   9757440\n",
       "Zylan Cheatham     New Orleans Pelicans       SF 1995-11-17     79568"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.sort_index().loc[\"Zach Collins\":]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Aaron Gordon</th>\n",
       "      <td>Orlando Magic</td>\n",
       "      <td>PF</td>\n",
       "      <td>1995-09-16</td>\n",
       "      <td>19863636</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Aaron Holiday</th>\n",
       "      <td>Indiana Pacers</td>\n",
       "      <td>PG</td>\n",
       "      <td>1996-09-30</td>\n",
       "      <td>2239200</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Abdel Nader</th>\n",
       "      <td>Oklahoma City Thunder</td>\n",
       "      <td>SF</td>\n",
       "      <td>1993-09-25</td>\n",
       "      <td>1618520</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Adam Mokoka</th>\n",
       "      <td>Chicago Bulls</td>\n",
       "      <td>G</td>\n",
       "      <td>1998-07-18</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Admiral Schofield</th>\n",
       "      <td>Washington Wizards</td>\n",
       "      <td>SF</td>\n",
       "      <td>1997-03-30</td>\n",
       "      <td>1000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Al Horford</th>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>C</td>\n",
       "      <td>1986-06-03</td>\n",
       "      <td>28000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                    Team Position   Birthday    Salary\n",
       "Name                                                                  \n",
       "Aaron Gordon               Orlando Magic       PF 1995-09-16  19863636\n",
       "Aaron Holiday             Indiana Pacers       PG 1996-09-30   2239200\n",
       "Abdel Nader        Oklahoma City Thunder       SF 1993-09-25   1618520\n",
       "Adam Mokoka                Chicago Bulls        G 1998-07-18     79568\n",
       "Admiral Schofield     Washington Wizards       SF 1997-03-30   1000000\n",
       "Al Horford            Philadelphia 76ers        C 1986-06-03  28000000"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.sort_index().loc[:\"Al Horford\"]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**NOTE**: I've commented out the code below so that the Notebook can run without raising an error."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [],
   "source": [
    "# nba.loc[\"Bugs Bunny\"]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 4.7.2 Extracting Rows by Index Position"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Team             Denver Nuggets\n",
       "Position                     PF\n",
       "Birthday    1999-04-03 00:00:00\n",
       "Salary                  1416852\n",
       "Name: Jarred Vanderbilt, dtype: object"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.iloc[300]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Brian Bowen</th>\n",
       "      <td>Indiana Pacers</td>\n",
       "      <td>SG</td>\n",
       "      <td>1998-10-02</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Marco Belinelli</th>\n",
       "      <td>San Antonio Spurs</td>\n",
       "      <td>SF</td>\n",
       "      <td>1986-03-25</td>\n",
       "      <td>5846154</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Jarred Vanderbilt</th>\n",
       "      <td>Denver Nuggets</td>\n",
       "      <td>PF</td>\n",
       "      <td>1999-04-03</td>\n",
       "      <td>1416852</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Louis King</th>\n",
       "      <td>Detroit Pistons</td>\n",
       "      <td>F</td>\n",
       "      <td>1999-04-06</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                Team Position   Birthday   Salary\n",
       "Name                                                             \n",
       "Brian Bowen           Indiana Pacers       SG 1998-10-02    79568\n",
       "Marco Belinelli    San Antonio Spurs       SF 1986-03-25  5846154\n",
       "Jarred Vanderbilt     Denver Nuggets       PF 1999-04-03  1416852\n",
       "Louis King           Detroit Pistons        F 1999-04-06    79568"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.iloc[[100, 200, 300, 400]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Louis King</th>\n",
       "      <td>Detroit Pistons</td>\n",
       "      <td>F</td>\n",
       "      <td>1999-04-06</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Kostas Antetokounmpo</th>\n",
       "      <td>Los Angeles Lakers</td>\n",
       "      <td>PF</td>\n",
       "      <td>1997-11-20</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Rodions Kurucs</th>\n",
       "      <td>Brooklyn Nets</td>\n",
       "      <td>PF</td>\n",
       "      <td>1998-02-05</td>\n",
       "      <td>1699236</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Spencer Dinwiddie</th>\n",
       "      <td>Brooklyn Nets</td>\n",
       "      <td>PG</td>\n",
       "      <td>1993-04-06</td>\n",
       "      <td>10605600</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                    Team Position   Birthday    Salary\n",
       "Name                                                                  \n",
       "Louis King               Detroit Pistons        F 1999-04-06     79568\n",
       "Kostas Antetokounmpo  Los Angeles Lakers       PF 1997-11-20     79568\n",
       "Rodions Kurucs             Brooklyn Nets       PF 1998-02-05   1699236\n",
       "Spencer Dinwiddie          Brooklyn Nets       PG 1993-04-06  10605600"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.iloc[400:404]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Shake Milton</th>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>SG</td>\n",
       "      <td>1996-09-26</td>\n",
       "      <td>1445697</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Christian Wood</th>\n",
       "      <td>Detroit Pistons</td>\n",
       "      <td>PF</td>\n",
       "      <td>1995-09-27</td>\n",
       "      <td>1645357</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                              Team Position   Birthday   Salary\n",
       "Name                                                           \n",
       "Shake Milton    Philadelphia 76ers       SG 1996-09-26  1445697\n",
       "Christian Wood     Detroit Pistons       PF 1995-09-27  1645357"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.iloc[:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Robin Lopez</th>\n",
       "      <td>Milwaukee Bucks</td>\n",
       "      <td>C</td>\n",
       "      <td>1988-04-01</td>\n",
       "      <td>4767000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Collin Sexton</th>\n",
       "      <td>Cleveland Cavaliers</td>\n",
       "      <td>PG</td>\n",
       "      <td>1999-01-04</td>\n",
       "      <td>4764960</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Ricky Rubio</th>\n",
       "      <td>Phoenix Suns</td>\n",
       "      <td>PG</td>\n",
       "      <td>1990-10-21</td>\n",
       "      <td>16200000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                              Team Position   Birthday    Salary\n",
       "Name                                                            \n",
       "Robin Lopez        Milwaukee Bucks        C 1988-04-01   4767000\n",
       "Collin Sexton  Cleveland Cavaliers       PG 1999-01-04   4764960\n",
       "Ricky Rubio           Phoenix Suns       PG 1990-10-21  16200000"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.iloc[447:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Jared Dudley</th>\n",
       "      <td>Los Angeles Lakers</td>\n",
       "      <td>PF</td>\n",
       "      <td>1985-07-10</td>\n",
       "      <td>2564753</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Max Strus</th>\n",
       "      <td>Chicago Bulls</td>\n",
       "      <td>SG</td>\n",
       "      <td>1996-03-28</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Kevon Looney</th>\n",
       "      <td>Golden State Warriors</td>\n",
       "      <td>C</td>\n",
       "      <td>1996-02-06</td>\n",
       "      <td>4464286</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Willy Hernangomez</th>\n",
       "      <td>Charlotte Hornets</td>\n",
       "      <td>C</td>\n",
       "      <td>1994-05-27</td>\n",
       "      <td>1557250</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                    Team Position   Birthday   Salary\n",
       "Name                                                                 \n",
       "Jared Dudley          Los Angeles Lakers       PF 1985-07-10  2564753\n",
       "Max Strus                  Chicago Bulls       SG 1996-03-28    79568\n",
       "Kevon Looney       Golden State Warriors        C 1996-02-06  4464286\n",
       "Willy Hernangomez      Charlotte Hornets        C 1994-05-27  1557250"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.iloc[-10:-6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Shake Milton</th>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>SG</td>\n",
       "      <td>1996-09-26</td>\n",
       "      <td>1445697</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PJ Washington</th>\n",
       "      <td>Charlotte Hornets</td>\n",
       "      <td>PF</td>\n",
       "      <td>1998-08-23</td>\n",
       "      <td>3831840</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Marial Shayok</th>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>G</td>\n",
       "      <td>1995-07-26</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Kendrick Nunn</th>\n",
       "      <td>Miami Heat</td>\n",
       "      <td>SG</td>\n",
       "      <td>1995-08-03</td>\n",
       "      <td>1416852</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Brook Lopez</th>\n",
       "      <td>Milwaukee Bucks</td>\n",
       "      <td>C</td>\n",
       "      <td>1988-04-01</td>\n",
       "      <td>12093024</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                             Team Position   Birthday    Salary\n",
       "Name                                                           \n",
       "Shake Milton   Philadelphia 76ers       SG 1996-09-26   1445697\n",
       "PJ Washington   Charlotte Hornets       PF 1998-08-23   3831840\n",
       "Marial Shayok  Philadelphia 76ers        G 1995-07-26     79568\n",
       "Kendrick Nunn          Miami Heat       SG 1995-08-03   1416852\n",
       "Brook Lopez       Milwaukee Bucks        C 1988-04-01  12093024"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.iloc[0:10:2]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 4.7.3 Extracting Values from Specific Columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Milwaukee Bucks'"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.loc[\"Giannis Antetokounmpo\", \"Team\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Position                     PG\n",
       "Birthday    1989-08-26 00:00:00\n",
       "Name: James Harden, dtype: object"
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.loc[\"James Harden\", [\"Position\", \"Birthday\"]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Team</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Russell Westbrook</th>\n",
       "      <td>Houston Rockets</td>\n",
       "      <td>38506482</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Anthony Davis</th>\n",
       "      <td>Los Angeles Lakers</td>\n",
       "      <td>27093019</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                 Team    Salary\n",
       "Name                                           \n",
       "Russell Westbrook     Houston Rockets  38506482\n",
       "Anthony Davis      Los Angeles Lakers  27093019"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.loc[\n",
    "    [\"Russell Westbrook\", \"Anthony Davis\"],\n",
    "    [\"Team\", \"Salary\"]\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Position                      C\n",
       "Birthday    1994-03-16 00:00:00\n",
       "Salary                 27504630\n",
       "Name: Joel Embiid, dtype: object"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.loc[\"Joel Embiid\", \"Position\":\"Salary\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Series([], Name: Joel Embiid, dtype: object)"
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.loc[\"Joel Embiid\", \"Salary\":\"Position\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "796806"
      ]
     },
     "execution_count": 83,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.iloc[57, 3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Brian Bowen</th>\n",
       "      <td>Indiana Pacers</td>\n",
       "      <td>SG</td>\n",
       "      <td>1998-10-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Aaron Holiday</th>\n",
       "      <td>Indiana Pacers</td>\n",
       "      <td>PG</td>\n",
       "      <td>1996-09-30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Troy Daniels</th>\n",
       "      <td>Los Angeles Lakers</td>\n",
       "      <td>SG</td>\n",
       "      <td>1991-07-15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Buddy Hield</th>\n",
       "      <td>Sacramento Kings</td>\n",
       "      <td>SG</td>\n",
       "      <td>1992-12-17</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                             Team Position   Birthday\n",
       "Name                                                 \n",
       "Brian Bowen        Indiana Pacers       SG 1998-10-02\n",
       "Aaron Holiday      Indiana Pacers       PG 1996-09-30\n",
       "Troy Daniels   Los Angeles Lakers       SG 1991-07-15\n",
       "Buddy Hield      Sacramento Kings       SG 1992-12-17"
      ]
     },
     "execution_count": 84,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.iloc[100:104, :3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Timestamp('1992-08-01 00:00:00')"
      ]
     },
     "execution_count": 85,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.at[\"Austin Rivers\", \"Birthday\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'PF'"
      ]
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.iat[263, 1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "14.4 µs ± 3.09 µs per loop (mean ± std. dev. of 7 runs, 100000 loops each)\n"
     ]
    }
   ],
   "source": [
    "%%timeit\n",
    "nba.at[\"Austin Rivers\", \"Birthday\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "16.6 µs ± 862 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)\n"
     ]
    }
   ],
   "source": [
    "%%timeit\n",
    "nba.loc[\"Austin Rivers\", \"Birthday\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "27.2 µs ± 3.21 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)\n"
     ]
    }
   ],
   "source": [
    "%%timeit\n",
    "nba.iat[263, 1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "26.6 µs ± 1.37 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)\n"
     ]
    }
   ],
   "source": [
    "%%timeit\n",
    "nba.iloc[263, 1]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4.8 Extracting Values from Series"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "29802321"
      ]
     },
     "execution_count": 91,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba[\"Salary\"].loc[\"Damian Lillard\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "29802321"
      ]
     },
     "execution_count": 92,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba[\"Salary\"].at[\"Damian Lillard\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2033160"
      ]
     },
     "execution_count": 93,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba[\"Salary\"].iloc[234]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2033160"
      ]
     },
     "execution_count": 94,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba[\"Salary\"].iat[234]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4.9 Renaming Columns or Rows"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['Team', 'Position', 'Birthday', 'Salary'], dtype='object')"
      ]
     },
     "execution_count": 95,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Date of Birth</th>\n",
       "      <th>Pay</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Shake Milton</th>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>SG</td>\n",
       "      <td>1996-09-26</td>\n",
       "      <td>1445697</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                            Team Position Date of Birth      Pay\n",
       "Name                                                            \n",
       "Shake Milton  Philadelphia 76ers       SG    1996-09-26  1445697"
      ]
     },
     "execution_count": 96,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.columns = [\"Team\", \"Position\", \"Date of Birth\", \"Pay\"]\n",
    "nba.head(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Pay</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Shake Milton</th>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>SG</td>\n",
       "      <td>1996-09-26</td>\n",
       "      <td>1445697</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Christian Wood</th>\n",
       "      <td>Detroit Pistons</td>\n",
       "      <td>PF</td>\n",
       "      <td>1995-09-27</td>\n",
       "      <td>1645357</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PJ Washington</th>\n",
       "      <td>Charlotte Hornets</td>\n",
       "      <td>PF</td>\n",
       "      <td>1998-08-23</td>\n",
       "      <td>3831840</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Derrick Rose</th>\n",
       "      <td>Detroit Pistons</td>\n",
       "      <td>PG</td>\n",
       "      <td>1988-10-04</td>\n",
       "      <td>7317074</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Marial Shayok</th>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>G</td>\n",
       "      <td>1995-07-26</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Austin Rivers</th>\n",
       "      <td>Houston Rockets</td>\n",
       "      <td>PG</td>\n",
       "      <td>1992-08-01</td>\n",
       "      <td>2174310</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Harry Giles</th>\n",
       "      <td>Sacramento Kings</td>\n",
       "      <td>PF</td>\n",
       "      <td>1998-04-22</td>\n",
       "      <td>2578800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Robin Lopez</th>\n",
       "      <td>Milwaukee Bucks</td>\n",
       "      <td>C</td>\n",
       "      <td>1988-04-01</td>\n",
       "      <td>4767000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Collin Sexton</th>\n",
       "      <td>Cleveland Cavaliers</td>\n",
       "      <td>PG</td>\n",
       "      <td>1999-01-04</td>\n",
       "      <td>4764960</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Ricky Rubio</th>\n",
       "      <td>Phoenix Suns</td>\n",
       "      <td>PG</td>\n",
       "      <td>1990-10-21</td>\n",
       "      <td>16200000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>450 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                               Team Position   Birthday       Pay\n",
       "Name                                                             \n",
       "Shake Milton     Philadelphia 76ers       SG 1996-09-26   1445697\n",
       "Christian Wood      Detroit Pistons       PF 1995-09-27   1645357\n",
       "PJ Washington     Charlotte Hornets       PF 1998-08-23   3831840\n",
       "Derrick Rose        Detroit Pistons       PG 1988-10-04   7317074\n",
       "Marial Shayok    Philadelphia 76ers        G 1995-07-26     79568\n",
       "...                             ...      ...        ...       ...\n",
       "Austin Rivers       Houston Rockets       PG 1992-08-01   2174310\n",
       "Harry Giles        Sacramento Kings       PF 1998-04-22   2578800\n",
       "Robin Lopez         Milwaukee Bucks        C 1988-04-01   4767000\n",
       "Collin Sexton   Cleveland Cavaliers       PG 1999-01-04   4764960\n",
       "Ricky Rubio            Phoenix Suns       PG 1990-10-21  16200000\n",
       "\n",
       "[450 rows x 4 columns]"
      ]
     },
     "execution_count": 97,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.rename(columns = { \"Date of Birth\": \"Birthday\" })"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "metadata": {},
   "outputs": [],
   "source": [
    "nba = nba.rename(columns = { \"Date of Birth\": \"Birthday\" })"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Team            Milwaukee Bucks\n",
       "Position                     PF\n",
       "Birthday    1994-12-06 00:00:00\n",
       "Pay                    25842697\n",
       "Name: Giannis Antetokounmpo, dtype: object"
      ]
     },
     "execution_count": 99,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.loc[\"Giannis Antetokounmpo\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "metadata": {},
   "outputs": [],
   "source": [
    "nba = nba.rename(\n",
    "    index = { \"Giannis Antetokounmpo\": \"Greek Freak\" }    \n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Team            Milwaukee Bucks\n",
       "Position                     PF\n",
       "Birthday    1994-12-06 00:00:00\n",
       "Pay                    25842697\n",
       "Name: Greek Freak, dtype: object"
      ]
     },
     "execution_count": 101,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.loc[\"Greek Freak\"]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4.10 Resetting an Index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Pay</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Team</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Philadelphia 76ers</th>\n",
       "      <td>SG</td>\n",
       "      <td>1996-09-26</td>\n",
       "      <td>1445697</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Detroit Pistons</th>\n",
       "      <td>PF</td>\n",
       "      <td>1995-09-27</td>\n",
       "      <td>1645357</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Charlotte Hornets</th>\n",
       "      <td>PF</td>\n",
       "      <td>1998-08-23</td>\n",
       "      <td>3831840</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Detroit Pistons</th>\n",
       "      <td>PG</td>\n",
       "      <td>1988-10-04</td>\n",
       "      <td>7317074</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Philadelphia 76ers</th>\n",
       "      <td>G</td>\n",
       "      <td>1995-07-26</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   Position   Birthday      Pay\n",
       "Team                                           \n",
       "Philadelphia 76ers       SG 1996-09-26  1445697\n",
       "Detroit Pistons          PF 1995-09-27  1645357\n",
       "Charlotte Hornets        PF 1998-08-23  3831840\n",
       "Detroit Pistons          PG 1988-10-04  7317074\n",
       "Philadelphia 76ers        G 1995-07-26    79568"
      ]
     },
     "execution_count": 102,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.set_index(\"Team\").head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Pay</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Shake Milton</td>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>SG</td>\n",
       "      <td>1996-09-26</td>\n",
       "      <td>1445697</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Christian Wood</td>\n",
       "      <td>Detroit Pistons</td>\n",
       "      <td>PF</td>\n",
       "      <td>1995-09-27</td>\n",
       "      <td>1645357</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>PJ Washington</td>\n",
       "      <td>Charlotte Hornets</td>\n",
       "      <td>PF</td>\n",
       "      <td>1998-08-23</td>\n",
       "      <td>3831840</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Derrick Rose</td>\n",
       "      <td>Detroit Pistons</td>\n",
       "      <td>PG</td>\n",
       "      <td>1988-10-04</td>\n",
       "      <td>7317074</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Marial Shayok</td>\n",
       "      <td>Philadelphia 76ers</td>\n",
       "      <td>G</td>\n",
       "      <td>1995-07-26</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             Name                Team Position   Birthday      Pay\n",
       "0    Shake Milton  Philadelphia 76ers       SG 1996-09-26  1445697\n",
       "1  Christian Wood     Detroit Pistons       PF 1995-09-27  1645357\n",
       "2   PJ Washington   Charlotte Hornets       PF 1998-08-23  3831840\n",
       "3    Derrick Rose     Detroit Pistons       PG 1988-10-04  7317074\n",
       "4   Marial Shayok  Philadelphia 76ers        G 1995-07-26    79568"
      ]
     },
     "execution_count": 103,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.reset_index().head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Pay</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Team</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Philadelphia 76ers</th>\n",
       "      <td>Shake Milton</td>\n",
       "      <td>SG</td>\n",
       "      <td>1996-09-26</td>\n",
       "      <td>1445697</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Detroit Pistons</th>\n",
       "      <td>Christian Wood</td>\n",
       "      <td>PF</td>\n",
       "      <td>1995-09-27</td>\n",
       "      <td>1645357</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Charlotte Hornets</th>\n",
       "      <td>PJ Washington</td>\n",
       "      <td>PF</td>\n",
       "      <td>1998-08-23</td>\n",
       "      <td>3831840</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Detroit Pistons</th>\n",
       "      <td>Derrick Rose</td>\n",
       "      <td>PG</td>\n",
       "      <td>1988-10-04</td>\n",
       "      <td>7317074</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Philadelphia 76ers</th>\n",
       "      <td>Marial Shayok</td>\n",
       "      <td>G</td>\n",
       "      <td>1995-07-26</td>\n",
       "      <td>79568</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                              Name Position   Birthday      Pay\n",
       "Team                                                           \n",
       "Philadelphia 76ers    Shake Milton       SG 1996-09-26  1445697\n",
       "Detroit Pistons     Christian Wood       PF 1995-09-27  1645357\n",
       "Charlotte Hornets    PJ Washington       PF 1998-08-23  3831840\n",
       "Detroit Pistons       Derrick Rose       PG 1988-10-04  7317074\n",
       "Philadelphia 76ers   Marial Shayok        G 1995-07-26    79568"
      ]
     },
     "execution_count": 104,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nba.reset_index().set_index(\"Team\").head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "metadata": {},
   "outputs": [],
   "source": [
    "nba = nba.reset_index().set_index(\"Team\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4.11 Coding Challenge"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 4.11.1 Problems"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 4.11.2 Solutions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Tremon Smith</td>\n",
       "      <td>Philadelphia Eagles</td>\n",
       "      <td>RB</td>\n",
       "      <td>1996-07-20</td>\n",
       "      <td>570000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Shawn Williams</td>\n",
       "      <td>Cincinnati Bengals</td>\n",
       "      <td>SS</td>\n",
       "      <td>1991-05-13</td>\n",
       "      <td>3500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Adam Butler</td>\n",
       "      <td>New England Patriots</td>\n",
       "      <td>DT</td>\n",
       "      <td>1994-04-12</td>\n",
       "      <td>645000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Derek Wolfe</td>\n",
       "      <td>Denver Broncos</td>\n",
       "      <td>DE</td>\n",
       "      <td>1990-02-24</td>\n",
       "      <td>8000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Jake Ryan</td>\n",
       "      <td>Jacksonville Jaguars</td>\n",
       "      <td>OLB</td>\n",
       "      <td>1992-02-27</td>\n",
       "      <td>1000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1650</th>\n",
       "      <td>Bashaud Breeland</td>\n",
       "      <td>Kansas City Chiefs</td>\n",
       "      <td>CB</td>\n",
       "      <td>1992-01-30</td>\n",
       "      <td>805000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1651</th>\n",
       "      <td>Craig James</td>\n",
       "      <td>Philadelphia Eagles</td>\n",
       "      <td>CB</td>\n",
       "      <td>1996-04-29</td>\n",
       "      <td>570000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1652</th>\n",
       "      <td>Jonotthan Harrison</td>\n",
       "      <td>New York Jets</td>\n",
       "      <td>C</td>\n",
       "      <td>1991-08-25</td>\n",
       "      <td>1500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1653</th>\n",
       "      <td>Chuma Edoga</td>\n",
       "      <td>New York Jets</td>\n",
       "      <td>OT</td>\n",
       "      <td>1997-05-25</td>\n",
       "      <td>495000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1654</th>\n",
       "      <td>Tajae Sharpe</td>\n",
       "      <td>Tennessee Titans</td>\n",
       "      <td>WR</td>\n",
       "      <td>1994-12-23</td>\n",
       "      <td>2025000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1655 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                    Name                  Team Position   Birthday   Salary\n",
       "0           Tremon Smith   Philadelphia Eagles       RB 1996-07-20   570000\n",
       "1         Shawn Williams    Cincinnati Bengals       SS 1991-05-13  3500000\n",
       "2            Adam Butler  New England Patriots       DT 1994-04-12   645000\n",
       "3            Derek Wolfe        Denver Broncos       DE 1990-02-24  8000000\n",
       "4              Jake Ryan  Jacksonville Jaguars      OLB 1992-02-27  1000000\n",
       "...                  ...                   ...      ...        ...      ...\n",
       "1650    Bashaud Breeland    Kansas City Chiefs       CB 1992-01-30   805000\n",
       "1651         Craig James   Philadelphia Eagles       CB 1996-04-29   570000\n",
       "1652  Jonotthan Harrison         New York Jets        C 1991-08-25  1500000\n",
       "1653         Chuma Edoga         New York Jets       OT 1997-05-25   495000\n",
       "1654        Tajae Sharpe      Tennessee Titans       WR 1994-12-23  2025000\n",
       "\n",
       "[1655 rows x 5 columns]"
      ]
     },
     "execution_count": 106,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nfl = pd.read_csv(\"nfl.csv\", parse_dates = [\"Birthday\"])\n",
    "nfl"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "metadata": {},
   "outputs": [],
   "source": [
    "nfl = nfl.set_index(\"Name\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "metadata": {},
   "outputs": [],
   "source": [
    "nfl = pd.read_csv(\"nfl.csv\", index_col = \"Name\", parse_dates = [\"Birthday\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Tremon Smith</th>\n",
       "      <td>Philadelphia Eagles</td>\n",
       "      <td>RB</td>\n",
       "      <td>1996-07-20</td>\n",
       "      <td>570000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Shawn Williams</th>\n",
       "      <td>Cincinnati Bengals</td>\n",
       "      <td>SS</td>\n",
       "      <td>1991-05-13</td>\n",
       "      <td>3500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Adam Butler</th>\n",
       "      <td>New England Patriots</td>\n",
       "      <td>DT</td>\n",
       "      <td>1994-04-12</td>\n",
       "      <td>645000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Derek Wolfe</th>\n",
       "      <td>Denver Broncos</td>\n",
       "      <td>DE</td>\n",
       "      <td>1990-02-24</td>\n",
       "      <td>8000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Jake Ryan</th>\n",
       "      <td>Jacksonville Jaguars</td>\n",
       "      <td>OLB</td>\n",
       "      <td>1992-02-27</td>\n",
       "      <td>1000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                Team Position   Birthday   Salary\n",
       "Name                                                             \n",
       "Tremon Smith     Philadelphia Eagles       RB 1996-07-20   570000\n",
       "Shawn Williams    Cincinnati Bengals       SS 1991-05-13  3500000\n",
       "Adam Butler     New England Patriots       DT 1994-04-12   645000\n",
       "Derek Wolfe           Denver Broncos       DE 1990-02-24  8000000\n",
       "Jake Ryan       Jacksonville Jaguars      OLB 1992-02-27  1000000"
      ]
     },
     "execution_count": 109,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nfl.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "New York Jets          58\n",
       "Kansas City Chiefs     56\n",
       "Washington Redskins    56\n",
       "New Orleans Saints     55\n",
       "San Francisco 49Ers    55\n",
       "Name: Team, dtype: int64"
      ]
     },
     "execution_count": 110,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# The two lines below are equivalent\n",
    "nfl.Team.value_counts().head()\n",
    "nfl[\"Team\"].value_counts().head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Kirk Cousins</th>\n",
       "      <td>Minnesota Vikings</td>\n",
       "      <td>QB</td>\n",
       "      <td>1988-08-19</td>\n",
       "      <td>27500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Jameis Winston</th>\n",
       "      <td>Tampa Bay Buccaneers</td>\n",
       "      <td>QB</td>\n",
       "      <td>1994-01-06</td>\n",
       "      <td>20922000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Marcus Mariota</th>\n",
       "      <td>Tennessee Titans</td>\n",
       "      <td>QB</td>\n",
       "      <td>1993-10-30</td>\n",
       "      <td>20922000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Derek Carr</th>\n",
       "      <td>Oakland Raiders</td>\n",
       "      <td>QB</td>\n",
       "      <td>1991-03-28</td>\n",
       "      <td>19900000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Jimmy Garoppolo</th>\n",
       "      <td>San Francisco 49Ers</td>\n",
       "      <td>QB</td>\n",
       "      <td>1991-11-02</td>\n",
       "      <td>17200000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                 Team Position   Birthday    Salary\n",
       "Name                                                               \n",
       "Kirk Cousins        Minnesota Vikings       QB 1988-08-19  27500000\n",
       "Jameis Winston   Tampa Bay Buccaneers       QB 1994-01-06  20922000\n",
       "Marcus Mariota       Tennessee Titans       QB 1993-10-30  20922000\n",
       "Derek Carr            Oakland Raiders       QB 1991-03-28  19900000\n",
       "Jimmy Garoppolo   San Francisco 49Ers       QB 1991-11-02  17200000"
      ]
     },
     "execution_count": 111,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nfl.sort_values(\"Salary\", ascending = False).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 112,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Team</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Chandler Jones</th>\n",
       "      <td>Arizona Cardinals</td>\n",
       "      <td>OLB</td>\n",
       "      <td>1990-02-27</td>\n",
       "      <td>16500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Patrick Peterson</th>\n",
       "      <td>Arizona Cardinals</td>\n",
       "      <td>CB</td>\n",
       "      <td>1990-07-11</td>\n",
       "      <td>11000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Larry Fitzgerald</th>\n",
       "      <td>Arizona Cardinals</td>\n",
       "      <td>WR</td>\n",
       "      <td>1983-08-31</td>\n",
       "      <td>11000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>David Johnson</th>\n",
       "      <td>Arizona Cardinals</td>\n",
       "      <td>RB</td>\n",
       "      <td>1991-12-16</td>\n",
       "      <td>5700000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Justin Pugh</th>\n",
       "      <td>Arizona Cardinals</td>\n",
       "      <td>G</td>\n",
       "      <td>1990-08-15</td>\n",
       "      <td>5000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Ross Pierschbacher</th>\n",
       "      <td>Washington Redskins</td>\n",
       "      <td>C</td>\n",
       "      <td>1995-05-05</td>\n",
       "      <td>495000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Kelvin Harmon</th>\n",
       "      <td>Washington Redskins</td>\n",
       "      <td>WR</td>\n",
       "      <td>1996-12-15</td>\n",
       "      <td>495000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Wes Martin</th>\n",
       "      <td>Washington Redskins</td>\n",
       "      <td>G</td>\n",
       "      <td>1996-05-09</td>\n",
       "      <td>495000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Jimmy Moreland</th>\n",
       "      <td>Washington Redskins</td>\n",
       "      <td>CB</td>\n",
       "      <td>1995-08-26</td>\n",
       "      <td>495000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Jeremy Reaves</th>\n",
       "      <td>Washington Redskins</td>\n",
       "      <td>SS</td>\n",
       "      <td>1996-08-29</td>\n",
       "      <td>495000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1655 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                   Team Position   Birthday    Salary\n",
       "Name                                                                 \n",
       "Chandler Jones        Arizona Cardinals      OLB 1990-02-27  16500000\n",
       "Patrick Peterson      Arizona Cardinals       CB 1990-07-11  11000000\n",
       "Larry Fitzgerald      Arizona Cardinals       WR 1983-08-31  11000000\n",
       "David Johnson         Arizona Cardinals       RB 1991-12-16   5700000\n",
       "Justin Pugh           Arizona Cardinals        G 1990-08-15   5000000\n",
       "...                                 ...      ...        ...       ...\n",
       "Ross Pierschbacher  Washington Redskins        C 1995-05-05    495000\n",
       "Kelvin Harmon       Washington Redskins       WR 1996-12-15    495000\n",
       "Wes Martin          Washington Redskins        G 1996-05-09    495000\n",
       "Jimmy Moreland      Washington Redskins       CB 1995-08-26    495000\n",
       "Jeremy Reaves       Washington Redskins       SS 1996-08-29    495000\n",
       "\n",
       "[1655 rows x 4 columns]"
      ]
     },
     "execution_count": 112,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nfl.sort_values(\n",
    "    by = [\"Team\", \"Salary\"],\n",
    "    ascending = [True, False]\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Team</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Philadelphia Eagles</th>\n",
       "      <td>Tremon Smith</td>\n",
       "      <td>RB</td>\n",
       "      <td>1996-07-20</td>\n",
       "      <td>570000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Cincinnati Bengals</th>\n",
       "      <td>Shawn Williams</td>\n",
       "      <td>SS</td>\n",
       "      <td>1991-05-13</td>\n",
       "      <td>3500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>New England Patriots</th>\n",
       "      <td>Adam Butler</td>\n",
       "      <td>DT</td>\n",
       "      <td>1994-04-12</td>\n",
       "      <td>645000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                Name Position   Birthday   Salary\n",
       "Team                                                             \n",
       "Philadelphia Eagles     Tremon Smith       RB 1996-07-20   570000\n",
       "Cincinnati Bengals    Shawn Williams       SS 1991-05-13  3500000\n",
       "New England Patriots     Adam Butler       DT 1994-04-12   645000"
      ]
     },
     "execution_count": 113,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nfl = nfl.reset_index().set_index(keys = \"Team\")\n",
    "nfl.head(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 114,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Team</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>New York Jets</th>\n",
       "      <td>Bronson Kaufusi</td>\n",
       "      <td>DE</td>\n",
       "      <td>1991-07-06</td>\n",
       "      <td>645000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>New York Jets</th>\n",
       "      <td>Darryl Roberts</td>\n",
       "      <td>CB</td>\n",
       "      <td>1990-11-26</td>\n",
       "      <td>1000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>New York Jets</th>\n",
       "      <td>Jordan Willis</td>\n",
       "      <td>DE</td>\n",
       "      <td>1995-05-02</td>\n",
       "      <td>754750</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>New York Jets</th>\n",
       "      <td>Quinnen Williams</td>\n",
       "      <td>DE</td>\n",
       "      <td>1997-12-21</td>\n",
       "      <td>495000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>New York Jets</th>\n",
       "      <td>Sam Ficken</td>\n",
       "      <td>K</td>\n",
       "      <td>1992-12-14</td>\n",
       "      <td>495000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                           Name Position   Birthday   Salary\n",
       "Team                                                        \n",
       "New York Jets   Bronson Kaufusi       DE 1991-07-06   645000\n",
       "New York Jets    Darryl Roberts       CB 1990-11-26  1000000\n",
       "New York Jets     Jordan Willis       DE 1995-05-02   754750\n",
       "New York Jets  Quinnen Williams       DE 1997-12-21   495000\n",
       "New York Jets        Sam Ficken        K 1992-12-14   495000"
      ]
     },
     "execution_count": 114,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nfl.loc[\"New York Jets\"].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 115,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Position</th>\n",
       "      <th>Birthday</th>\n",
       "      <th>Salary</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Team</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>New York Jets</th>\n",
       "      <td>Ryan Kalil</td>\n",
       "      <td>C</td>\n",
       "      <td>1985-03-29</td>\n",
       "      <td>2400000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                     Name Position   Birthday   Salary\n",
       "Team                                                  \n",
       "New York Jets  Ryan Kalil        C 1985-03-29  2400000"
      ]
     },
     "execution_count": 115,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nfl.loc[\"New York Jets\"].sort_values(\"Birthday\").head(1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4.12 Summary"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
